<?php
/*
 * CakeMap -- a google maps integrated application built on CakePHP framework.
 * Copyright (c) 2005 Garrett J. Woodworth : gwoo@rd11.com
 * rd11,inc : http://rd11.com
 *
 * @author      gwoo <gwoo@rd11.com>
 * @version     0.10.1311_pre_beta
 * @license     OPPL
 *
 * Modified by 	Mahmoud Lababidi <lababidi@bearsontherun.com>
 * Date			Dec 16, 2006
 * 
 *
 */
class GoogleMapHelper extends Helper {

	var $errors = array();

	var $key = "ABQIAAAAfrYkvkgINrPXKRwuhTJIYhR8fPsS8ERwNSCqtzsazxQ04Wv7exT4tEuyY5Ra8oNoO8nHfYYeK9IdMQ";

	function map($default, $style = 'width: 400px; height: 400px' )
	{
		$out = "<div id=\"map_canvas\"";
		$out .= isset($style) ? "style=\"".$style."\"" : null;
		$out .= " ></div>";
		$out .= "
		<script type=\"text/javascript\">
		//<![CDATA[

		if (GBrowserIsCompatible()) 
		{
			var map = new GMap2(document.getElementById(\"map_canvas\"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(36.9891, -121.934), 13);
		}
		//]]>
		</script>";
		 return $out;
	}

	function addMarkers(&$data, $icon=null)
	{
		$out = "
			<script type=\"text/javascript\">
			//<![CDATA[
			if (GBrowserIsCompatible()) 
			{
			";				
			$i = 0;
			foreach($data as $point){
										
				$out .="var point = new GLatLng(".$point['Point']['latitude'].",".$point['Point']['longitude'].");";
				if(!isset($point['Image'][0]["Thumbnail"])){
					$out .="var marker".$i."=new GMarker(point);
							GEvent.addListener(marker".$i.", 'click', function() {  
  								marker".$i.".openInfoWindowHtml('<table width=\"250\" border=\"0\" cellspacing=\"0\" cellspacing=\"0\" ><tr><td colspan=\"2\" align=\"left\">".$point["Post"]["title"]."</td></tr><tr><td width=\"50%\" align=\"left\">Logo</td><td width=\"50%\" align=\"right\">by Marc</td></tr></table>');  
							});";
					
					$out .="map.addOverlay(marker".$i.");";
				}else{
					$out .="var blueIcon = new GIcon(G_DEFAULT_ICON);
					//blueIcon.image = \"http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png\";
					//blueIcon.image = \"http://www.jellyfish.marcfg.com/img/thumbnails/dining_CafeSparrow.jpg\";
					blueIcon.image = \"http://www.jellyfish.marcfg.com/img/".$point["Image"][0]["Thumbnail"]["path_small"]."\";
					blueIcon.iconSize = new GSize(40, 40);
            		markerOptions = { icon:blueIcon };"; 
					
					$out .="var marker".$i."=new GMarker(point,markerOptions);
							GEvent.addListener(marker".$i.", 'click', function() {  
  								marker".$i.".openInfoWindowHtml('<table id=\"window_info\"><tr><td id=\"info_title\" colspan=\"2\">".$point["Post"]["title"]."</td></tr><tr><td id=\"info_picture\" colspan=\"2\"><a href=\"/posts/view/".$point["Post"]["id"]."\"><img src=\"http://www.jellyfish.marcfg.com/img/".$point["Image"][0]["Thumbnail"]["path_big"]."\" width=\"200\" height=\"200\" /></a></td></tr><tr><td id=\"info_logo\" width=\"50%\">Logo</td><td id=\"info_user\" width=\"50%\">by Marc</td></tr></table>');  
							});";
					
					$out .="map.addOverlay(marker".$i.");";
				}
				$i++;
			}
				
			
		$out .=	"} 
				//]]>
			</script>";
		return $out;
	}
	

}
?>